from datetime import date
from django import forms
from lotto.const import GAMES, MONTHS, YEARS, QUANTITY



class ModeForm (forms.Form):
    mode = forms.ChoiceField (choices = GAMES, widget = forms.Select ()); 
    
    def __init__ (self, *args, **kwargs):
        super (ModeForm, self).__init__ (*args, **kwargs);
        self.fields['mode'].widget.attrs['title'] = 'Rodzaj gry liczbowej';


class MapForm (forms.Form):
    mode = forms.ChoiceField (choices = GAMES, widget = forms.Select ());
    month = forms.ChoiceField (choices = MONTHS, widget = forms.Select ());
    year = forms.ChoiceField (widget = forms.Select ());
    
    def __init__ (self, mode, *args, **kwargs):
        super (MapForm, self).__init__ (*args, **kwargs);
        self.fields['year'].choices = ((i, i) for i in xrange(YEARS[mode], date.today ().year + 1));
        self.fields['mode'].widget.attrs['title'] = 'Rodzaj gry liczbowej';


class CheckForm (forms.Form):
    mode = forms.ChoiceField (choices = GAMES, widget = forms.Select ()); 
    date = forms.CharField (max_length = 10);
    quantity = forms.ChoiceField (choices = QUANTITY, widget = forms.Select ());
    nums = forms.MultipleChoiceField (widget = forms.CheckboxSelectMultiple ());
    
    def __init__ (self, value = None, *args, **kwargs):
        super (CheckForm, self).__init__ (*args, **kwargs);
        self.fields['mode'].widget.attrs['title'] = 'Rodzaj gry liczbowej';
        self.fields['date'].widget.attrs['title'] = 'Data';
        self.fields['quantity'].widget.attrs['title'] = 'Liczba kolejnych losowan od wybranej daty';
        if value:
            self.fields['nums'].choices = ((i, i) for i in xrange (1, value));
        else:
            self.fields['nums'].choices = ((i, i) for i in xrange (1, 50));


class LottoForm (forms.Form):
    mode = forms.ChoiceField (choices = GAMES, widget = forms.Select ()); 
    date = forms.CharField (max_length = 10);
    
    def __init__ (self, *args, **kwargs):
        super (LottoForm, self).__init__ (*args, **kwargs);
        self.fields['mode'].widget.attrs['title'] = 'Rodzaj gry liczbowej';
        self.fields['date'].widget.attrs['title'] = 'Data';


class PairForm (forms.Form):
    mode = forms.ChoiceField (choices = GAMES, widget = forms.Select ()); 
    date = forms.CharField (max_length = 10);
    num = forms.IntegerField (max_value = 80);
    
    def __init__ (self, *args, **kwargs):
        super (PairForm, self).__init__ (*args, **kwargs);
        self.fields['mode'].widget.attrs['title'] = 'Rodzaj gry liczbowej';
        self.fields['date'].widget.attrs['title'] = 'Data';
        self.fields['num'].widget.attrs['title'] = 'Liczba';

